
(deftemplate dama
    (slot nume)
    (slot x)
    (slot y)
    )

(foreach ?d (create$ d1 d2 d3 d4)
    (foreach ?i (create$ 1 2 3 4)
    	(foreach ?j (create$ 1 2 3 4)
            (assert (dama (nume ?d) (x ?i) (y ?j)))
    )
   )
)


(defrule rezolvare
    
    ?idfapt1 <- (dama (nume d1)(x ?x1) (y ?y1)) ; iau id-ul fiecarei dame pt a o scoate din BD dupa ce a gasit'o pt ca sa nu mai af64 de solutii
    ?idfapt2 <- (dama (nume d2)(x ?x2) (y ?y2))
    ?idfapt3 <- (dama (nume d3)(x ?x3) (y ?y3))
    ?idfapt4 <- (dama (nume d4)(x ?x4) (y ?y4))
    
    
    (dama (nume d1)(x ?x1) (y ?y1))
    (dama (nume d2)(x ?x2) (y ?y2))
    (dama (nume d3)(x ?x3) (y ?y3))
    (dama (nume d4)(x ?x4) (y ?y4))
    (test (neq ?x1 ?x2))
    (test (neq ?x1 ?x3))
    (test (neq ?x1 ?x4))
    (test (neq ?x2 ?x3))
    (test (neq ?x2 ?x4))
    (test (neq ?x3 ?x4))
    (test (neq ?y1 ?y2))
    (test (neq ?y1 ?y3))
    (test (neq ?y1 ?y4))
    (test (neq ?y2 ?y3))
    (test (neq ?y2 ?y4))
    (test (neq ?y3 ?y4))
    ; -------------
    
    (test (neq (- ?x1 ?y1) (- ?x2 ?y2)))
    (test (neq (- ?x1 ?y1) (- ?x3 ?y3)))
    (test (neq (- ?x1 ?y1) (- ?x4 ?y4)))
    (test (neq (- ?x2 ?y2) (- ?x3 ?y3)))
    (test (neq (- ?x2 ?y2) (- ?x4 ?y4)))
    (test (neq (- ?x3 ?y3) (- ?x4 ?y4)))
    
    (test (neq (+ ?x1 ?y1) (+ ?x2 ?y2)))
    (test (neq (+ ?x1 ?y1) (+ ?x3 ?y3)))
    (test (neq (+ ?x1 ?y1) (+ ?x4 ?y4)))
    (test (neq (+ ?x2 ?y2) (+ ?x3 ?y3)))
    (test (neq (+ ?x2 ?y2) (+ ?x4 ?y4)))
    (test (neq (+ ?x3 ?y3) (+ ?x4 ?y4)))
    
    =>
    (retract ?idfapt1) ; scot id-ul fiecarei dame din BD
    (retract ?idfapt2)
    (retract ?idfapt3)
    (retract ?idfapt4)
    (printout t crlf "*********Solutie" crlf)
    (printout t "dama 1 se afla pe poz " ?x1 " " ?y1 crlf)
    (printout t "dama 2 se afla pe poz " ?x2 " " ?y2 crlf)
    (printout t "dama 3 se afla pe poz " ?x3 " " ?y3 crlf)
    (printout t "dama 4 se afla pe poz " ?x4 " " ?y4 crlf)
)

(run) 
(agenda)  